//index.js
//获取应用实例
const app = getApp()

Component({
   options: {
      addGlobalClass: true,
      multipleSlots: true
   },
  data: {
     StatusBar: app.globalData.StatusBar,
     CustomBar: app.globalData.CustomBar,
     Custom: app.globalData.Custom,
     temperature:app.globalData.weather.temperature,
     weather:app.globalData.weather.weather,
     showModal:'',
     currentTem:24,
     airStat:'hot',
     openAir:true,
     lightOpen:true,
     date:app.globalData.date,
     serviceStat:'无',
     light:false
     

  },
  attached:function(){
     if(app.globalData.weather){
        this.setData({
           temperature: app.globalData.weather.temperature,
           weather: app.globalData.weather.weather,
        })
     }else{
        app.weatherCallBack = res=>{
           this.setData({
              temperature: res.liveData.temperature,
              weather: res.liveData.weather
           })
        }
     }
  },

  methods:{
   showModal_(e){
      const name = e.currentTarget.dataset.name
      this.setData({
         showModal:name
      })
   },
   hideModal(){
      this.setData({
         showModal:''
      })
   },
   switchOpen(e){
      let state = e.detail.value
      this.setData({
         openAir:state,
      })
      if(!state){
         this.setData({
            airStat:'',
            currentTem:''
         })
      }

   },
   choseLight(e){
      wx.vibrateShort({})
    
      this.setData({
         light:!this.data.light
      })
   },
   addTem(){
      this.setData({
         currentTem:this.data.currentTem + 1
      })
   },
   minusTem() {
      this.setData({
         currentTem: this.data.currentTem -1
      })
   },
   choseClod(){
      this.setData({
         airStat:'clod',
         currentTem:25,
         openAir: true
      })
   },
   choseHot() {
      this.setData({
         airStat: 'hot',
         currentTem:25,
         openAir:true
      })
   },
   choseWindy() {
      this.setData({
         airStat: 'windy',
         currentTem:'',
         openAir: true
      })
   },
   openLight(e){
      
      this.setData({
         lightOpen: e.detail.value
      })
   },
    openRoom(){
        wx.scanCode({
            onlyFromCamera: true,
            success(res) {
                console.log(res)
            }
        })
    },
   serviceChose(e){
      this.setData({
         serviceStat:e.currentTarget.dataset.service,
         showModal: ''
      })
   },
  }
})
